﻿@inherits LayoutComponentBase

<MudThemeProvider IsDarkMode="@IsDarkMode" Theme="CurrentTheme"/>
<MudDialogProvider/>
<MudSnackbarProvider/>

<MudLayout>
    <MudAppBar Elevation="0" Color="Color.Inherit">
        <MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@DrawerToggle"/>
        <MudSpacer/>
        @foreach (var appBarItem in AppBarService.AppBarItems)
        {
            @appBarItem
        }

        <MudIconButton Icon="@Icons.Material.Outlined.Book" Color="Color.Inherit" Link="https://v3.elsaworkflows.io/" Target="_blank" Title="Documentation"/>
        <MudIconButton Icon="@Icons.Custom.Brands.GitHub" Color="Color.Inherit" Link="https://github.com/elsa-workflows/elsa-core" Target="_blank" Title="Source code"/>

        @if (IsDarkMode)
        {
            <MudToggleIconButton Icon="@Icons.Material.Outlined.LightMode" Color="Color.Inherit" @onclick="ToggleDarkMode"></MudToggleIconButton>
        }
        else
        {
            <MudToggleIconButton Icon="@Icons.Material.Outlined.DarkMode" Color="Color.Inherit" @onclick="ToggleDarkMode"></MudToggleIconButton>
        }
    </MudAppBar>
    <MudDrawer @bind-Open="_drawerOpen" Elevation="0" ClipMode="DrawerClipMode.Always">
        <MudDrawerHeader>
            <MudStack>
                    <div class="d-flex gap-2 align-center">
                        <MudImage Src="_content/Elsa.Studio.Shell/img/icon.png" ObjectFit="ObjectFit.ScaleDown" Fluid="true" Width="32" Height="32"></MudImage>
                        <MudText Typo="Typo.h6">ELSA 3.0</MudText>
                    </div>
                <div>
                    <ServerPackageVersion/>
                </div>
            </MudStack>
        </MudDrawerHeader>
        <div class="mt-10">
            <NavMenu/>
        </div>
    </MudDrawer>
    <MudMainContent>
        <ErrorBoundary>
            <ChildContent>
                @Body
            </ChildContent>
            <ErrorContent>
                @if (context is UnauthorizedAccessException)
                {
                    @UnauthorizedComponent
                }
                else
                {
                    <Well>
                        <MudAlert Severity="Severity.Error" Variant="Variant.Filled">
                            @context.GetType().Name: @context.Message
                        </MudAlert>
                    </Well>
                }
            </ErrorContent>
        </ErrorBoundary>

    </MudMainContent>
</MudLayout>